import java.io.Reader;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class MyThreadPool{
    BlockingQueue<Runnable> queue=new ArrayBlockingQueue<>(1000);
    public MyThreadPool(int caption){
        for (int i = 0; i < caption; i++) {
            Thread t=new Thread(()->{
               while (true){
                   try {
                       Runnable runnable=queue.take();
                       runnable.run();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
            });
            t.start();
        }
    }
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
}



public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool=new MyThreadPool(4);
        for (int i = 0; i < 1000; i++) {
            int id=i;
            myThreadPool.submit(()->{
                System.out.println("执行任务"+id+","+Thread.currentThread().getName());
            });
        }
    }
}
